import router from './router'

// 无权限鉴权白名单
const whiteList = ['login']
const loginRoutePath = '/user/login'

// 路由前置守卫
router.beforeEach((to, from, next) => {
  if ('login' === to.name) {
    sessionStorage.clear()
    next()
  } else if (whiteList.includes(to.name)) {
    next()
  }
  const token = sessionStorage.getItem('Access-Token')
  if (null != token) {
    // 有token
    next()
  } else {
    // 无token，跳转到登录页
    next({ path: loginRoutePath })
  }
})
